﻿using Kz.Telegram.Bot.Console.HandleUpdate.Enums;
using Kz.Telegram.Bot.Console.HandleUpdate.Models;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace Kz.Telegram.Bot.Console.HandleUpdate.MessageTypeHandler.MessageText
{
    /// <summary>
    /// Bot指令消息处理
    /// </summary>
    public class MessageTextBotCommandHandler : IHandler
    {
        public async Task Handle(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
        {
            var msg = update.Message!;
            var typ = msg.Chat.Type!;   //判断是从群组内发出，还是从机器人单聊中发出

            //开始
            if (msg.Text == "/start" || msg.Text == $"/start@{Bot.UserName}")
            {
                if (typ == ChatType.Supergroup)
                {

                    List<InlineKeyboardButton> buttons = new List<InlineKeyboardButton>()
                    {
                        InlineKeyboardButton.WithCallbackData("😎 发起投票", CallbackQueryModel.Create(InlineCallbackEnum.SendPoll, string.Empty))
                    };

                    InlineKeyboardMarkup markup = new InlineKeyboardMarkup(buttons);



                    string welcome = System.IO.File.ReadAllText("Texts/welcome_from_group.txt");
                    await botClient.SendMessage(msg.Chat.Id, welcome,
                        cancellationToken: cancellationToken,
                        replyParameters: new ReplyParameters() { MessageId = msg.MessageId },
                        //disableWebPagePreview: false,
                        parseMode: ParseMode.Html,
                        replyMarkup: markup);
                }
                else
                {
                    InlineKeyboardMarkup buttons = new[]
                    {
                        InlineKeyboardButton.WithUrl("加入我的群组","https://t.me/kz_laosiji_bot?startgroup=c"),
                    };
                    string welcome = System.IO.File.ReadAllText("Texts/welcome_from_private.txt");
                    await botClient.SendMessage(msg.Chat.Id, welcome,
                        cancellationToken: cancellationToken,
                        parseMode: ParseMode.Html,
                        linkPreviewOptions: new LinkPreviewOptions() { IsDisabled = true },
                        //disableWebPagePreview: false,
                        replyMarkup: buttons);
                }
                return;
            }

            //禁言
            if (msg.Text == "/mute" || msg.Text == $"/mute@{Bot.UserName}")
            {
                //await botClient.BanChatSenderChatAsync(msg.Chat.Id, 1111111111, cancellationToken: cancellationToken);
            }

            //解除禁言
            if (msg.Text == "/unmute" || msg.Text == $"/unmute@{Bot.UserName}")
            {
                //await botClient.UnbanChatSenderChatAsync(msg.Chat.Id, 1111111111, cancellationToken: cancellationToken);
            }

            //封禁
            if (msg.Text == "/ban" || msg.Text == $"/ban@{Bot.UserName}")
            {
                //await botClient.BanChatMemberAsync(msg.Chat.Id, 111111111, cancellationToken: cancellationToken);
            }

            //解除封禁
            if (msg.Text == "/unban" || msg.Text == $"/unban@{Bot.UserName}")
            {
                //await botClient.UnbanChatMemberAsync(msg.Chat.Id, 111111111, cancellationToken: cancellationToken);
            }

            //踢出
            if (msg.Text == "/kick" || msg.Text == $"/kick@{Bot.UserName}")
            {
                //await botClient.BanChatMemberAsync(msg.Chat.Id, msg.From!.Id, DateTime.Now.AddMinutes(1), cancellationToken: cancellationToken, revokeMessages: true);
            }

        }
    }
}